%This scripts shows the normalized volume of a spherical cap as its
%distance from the center of the sphere is varied from -R (0 vol) to R
%(full vol) 


%2011-01-25 Making a plot of the volume as a function of dimension and z.
%removed hypergeometric: %vBminusC(ind,d) = 0.5 + (z(ind)/r)*(gamma(d/2+1)/sqrt(pi)/gamma(d/2+0.5))*hypergeom([0.5,0.5-d/2],1.5,(z(ind)/r)^2);

%2011-01-07 checking the relative volume of the spherical cap (smaller portion)

clc;
clear all;
close all;

r = 1; % max radius
z = 0:0.1:r; %height from the center varying from 0 to full.
dMax = 9; % upto this dimension

for d=1:dMax % outer loop: for each dimension value
    for ind=1:length(z) % inner loop: for each height value
        vBminusCnormalized(ind,d) = 1 - 0.5*betainc(1 - z(ind)^2/r^2, 0.5+d/2,0.5);
        vCnormalized(ind,d) = 1 - vBminusCnormalized(ind,d);
    end
end

h4=figure;
for d=1:dMax
    plot([z z+1]',[ flipdim(vCnormalized(:,d),1); vBminusCnormalized(:,d)],'.-','color',[rand,rand,rand]); hold on;
    M(d,:) = strcat(['d = ' int2str(d)]);
    set(gca,'xticklabel',[1 0 1]);
end

set(gca, 'Fontsize',30);
width=2;
set(0,'DefaultAxesLineWidth',width);
set(0,'DefaultLineLineWidth',width);
get(0,'Default');
set(gca,'LineWidth', width);   
h4 = get(gca,'children'); 
title('Normalized Vol(B_{1}\cap H_{z})');
xlabel('z: Distance of H_{z} from origin');
ylabel('Volume');
legend(M,'Location','SouthEast');